<template>

  <a-card :bordered="false" class="card-area">

      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <!-- 搜索区域 -->
        <a-form layout="inline">
          <a-form-item label="实体类名" >
            <a-input  v-model="queryParam.className.value"></a-input>
          </a-form-item>
          <a-form-item label="实体类描述" >
            <a-input  v-model="queryParam.comment.value"></a-input>
          </a-form-item>
          <a-form-item>
            <span  class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery">查询</a-button>
               <a-button   @click="handleAdd" type="primary" icon="plus">新增</a-button>
              <a-button  type="danger" icon="delete"  v-if="selectedRowKeys.length > 0"  @click="batchDel">批量删除</a-button>
            </span>
          </a-form-item>
        </a-form>
      </div>


      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择&nbsp;<a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @change="handleTableChange">
          <span slot="ellipsis" slot-scope="text">
            <ak-ellipsis :value="text" :length="100"/>
          </span>
          <span slot="action" slot-scope="text, record" class="table-operator">
            <a  @click="handleEdit(record)">编辑</a>
            <a  @click="handleGen(record.id)">生成代码</a>
          </span>


        </a-table>
      </div>

        <CodeGenClassModal ref="modalForm" @ok="modalFormOk"></CodeGenClassModal>
  </a-card>
</template>

    <script>
      import  AkfhListMixin  from '../../mixin/AkfhListMixin';
      import AkEllipsis from '../../components/akfh/AkEllipsis';
      import AkDate from '../../components/akfh/AkDate';
      import { codeGenClassUrl} from '../../api/url';
      import { getAction, postAction } from '../../api/manage'
      import CodeGenClassModal from "./modal/CodeGenClassModal";
      import qs from 'qs';

      export default {
        name: "CodeGenClassList",
        mixins:[AkfhListMixin],
        components: {
          CodeGenClassModal,
          AkDate,AkEllipsis
        },
        data () {
          return {
            departTree:[],
            description: '实体描述',
            // 查询条件
            queryParam: {
              className:{
                type:'like',
                column:'className',
                value:''
              },
              comment:{
                type:'like',
                column:'comment',
                value:''
              }
            },
            // 表头
            columns: [
              {
                title: '#',
                dataIndex: '',
                key:'rowIndex',
                width:60,
                align:"center",
                customRender:function (t,r,index) {
                  return parseInt(index)+1;
                }
              },
              {
                title: '类名',
                align:"center",
                dataIndex: 'className',
                scopedSlots: { customRender: 'ellipsis' },
              },
              {
                title: '描述',
                align:"center",
                dataIndex: 'comment',
                scopedSlots: { customRender: 'ellipsis' },
              },
              {
                title: '操作',
                dataIndex: 'action',
                width:160,
                align:"center",
                scopedSlots: { customRender: 'action' },
              }
            ],
            url: codeGenClassUrl,
          }
        },

        mounted(){

        },
        methods: {
          handleGen(id){
            this.loading = true;
            postAction(this.url.gen, qs.stringify({id}))
              .then(res=>{
                if(res.success){
                  this.$message.success(res.message);
                }
              }).finally(()=>{
                this.loading = false;
            })
          }
        }
      }
    </script>
    <style scoped>
    </style>
